package com.feituan.core.persistence.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.feituan.core.persistence.mapper.RechargeRecordMapper;
import com.feituan.core.persistence.service.IRechargeRecordService;
import com.feituan.core.pojo.entity.Order;
import com.feituan.core.pojo.entity.RechargeRecord;
import com.feituan.core.util.OrderNumberGenerator;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class RechargeRecordServiceImpl extends ServiceImpl<RechargeRecordMapper, RechargeRecord> implements IRechargeRecordService {


    /**
     * 新增
     * @param rechargeRecord
     * @return
     */
    @Override
    public Long saveRecord(RechargeRecord rechargeRecord) {
        rechargeRecord.setStatus(1);
        rechargeRecord.setCreateTime(new Date());
        rechargeRecord.setNumber("CZ" + OrderNumberGenerator.generateOrderNumber());
        this.getBaseMapper().insert(rechargeRecord);

        return rechargeRecord.getId();
    }

    @Override
    public RechargeRecord selectById(Long id) {
        return this.getBaseMapper().selectById(id);
    }

    @Override
    public RechargeRecord selectByNumber(String number) {

        return this.lambdaQuery().eq(RechargeRecord::getNumber,number).one();
    }
}
